//
//  YLVisitorTableViewController.swift
//  weiBo
//
//  Created by 杨雷 on 2016/12/1.
//  Copyright © 2016年 Yang.L. All rights reserved.
//

import UIKit

class YLVisitorTableViewController: UITableViewController {
    
    //是否登录的标记
    var islogin: Bool = YLUserAccountViewModel.sharedUserAccount.isLogin
    
    //访客视图
    var visitorV :YLVisitorView?
    
    override func loadView() {
        if islogin == false {
            //未登录
            visitorV = YLVisitorView()
            
            visitorV?.callBack = {[weak self] in
                // 登陆和注册按钮 执行
                self?.requestOAuth()
            }
            visitorV?.delegate = self
            //设置这个View 为视图
            view = visitorV
            //设置导航栏按钮
            setupNavUI()
            
            
        } else {
            //已登录
            super.loadView()
        }
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    private func setupNavUI () {
        
        //设置按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(registerBtnAction))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(loginBtnAction))
        
    }
    
    //注册按钮点击事件
    @objc private func registerBtnAction() {
        print("注册")
        requestOAuth()
    }
    
    //登录按钮点击事件
    @objc private func loginBtnAction() {
        print("登录")
        requestOAuth()
    }
    
    //请求第三方
    private func requestOAuth () {
        let oAuth = YLOAuthViewController ()
        let nav = YLNavigationViewController(rootViewController: oAuth)
        present(nav, animated: true, completion: nil)
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}

extension YLVisitorTableViewController : YLVisitorViewDelegate {
    func loginOperation() {
        //代理方法
    }
}










